home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
sound
/
fftscop4.zip
/
FT-SCOPE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-30
|
29KB
|
1,261 lines
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
#include <mem.h>
#include <math.h>
#define TWO_PI ((double)2.0 * M_PI)
typedef unsigned char DacPalette256[256][3];
unsigned char far *VGAmem;
struct text_info tiGFX;
struct REGPACK regp;
union REGS reg;
int Linecolor=1,WritePage=0,HighSpeed=0,Triggerbuffer=999,winX=1;
int minX=0,minY=0,maxx=320,maxy=200;
DacPalette256 Hallo;
/* Globals */
int samples, power;
double real[2048], imag[2048], max, min, Pegel=10,FFTmax;
FILE *fpi, *fpo;
/* Prototypes and forward declarations */
void fft(void), max_amp(void);
int permute(int);
double magnitude(int);
void dspwrite ( unsigned char );
unsigned char dspread ( void );
unsigned Buffer[2048];
unsigned SBuffer[8900];
unsigned char far *data;
unsigned char far *aligned;
unsigned char far aligned_physical;
/* Setvgapalette256 sets the entire 256 color palette */
/* PalBuf contains RGB values for all 256 colors */
/* R,G,B values range from 0 to 63 */
/* Usage: */
/* DacPalette256 dac256; */
/* */
/* setvgapalette256(&dac256); */
void setvgapalette256(DacPalette256 *PalBuf)
{
regp.r_ax = 0x1012;
regp.r_bx = 0;
regp.r_cx = 256;
regp.r_es = FP_SEG(PalBuf);
regp.r_dx = FP_OFF(PalBuf);
intr(0x10,®p);
}
void Grafik(int GFXmode) // 13, 14, 17mono, 18, 19vga, -1,3
{ //320x200, 640x200, 640x480, 640x480, 320x200, text
VGAmem=(char far *)MK_FP(0xa000,0);
if (GFXmode>=0)
{
gettextinfo(&tiGFX);
regp.r_ax = GFXmode;
intr(0x10,®p);
}
if (GFXmode<0)
{
regp.r_ax = tiGFX.currmode;
intr(0x10,®p);
}
}
void Putpixel(int x, int y)
{
reg.h.ah = 0x0c;
reg.h.al = Linecolor;
reg.h.bh = WritePage;
reg.x.cx = x;
reg.x.dx = y;
int86(0x10,®,®);
}
void singlecolor256(int nr,int r,int g,int b)
{
reg.h.ah = 0x10;
reg.h.al = 0x10;
reg.x.bx = nr;
reg.h.ch = g;
reg.h.cl = b;
reg.h.dh = r;
int86(0x10,®,®);
}
void singlecolor16(int nr,int r,int g,int b)
{
reg.h.ah=0x10;
reg.h.al=0x07;
reg.h.bl=nr;
int86(0x10,®,®);
nr=reg.h.bh;
reg.h.ah = 0x10;
reg.h.al = 0x10;
reg.x.bx = nr;
reg.h.ch = g;
reg.h.cl = b;
reg.h.dh = r;
int86(0x10,®,®);
}
void MakePalette()
{
int frag;
for(frag=0;frag<256;frag++)
{
if(frag<32)
{
Hallo[frag][0]=0;
Hallo[frag][1]=0;
Hallo[frag][2]=2*frag;
}
if((frag>=32)&&(frag<96))
{
Hallo[frag][0]=0;
Hallo[frag][1]=(frag-32);
Hallo[frag][2]=(95-frag);
}
if((frag>=96)&&(frag<128))
{
Hallo[frag][0]=2*(frag-96);
Hallo[frag][1]=63;
Hallo[frag][2]=0;
}
if((frag>=128)&&(frag<192))
{
Hallo[frag][0]=63;
Hallo[frag][1]=(191-frag);
Hallo[frag][2]=(frag-128);
}
if(frag>=192)
{
Hallo[frag][0]=63;
Hallo[frag][1]=0;
Hallo[frag][2]=0;
if(frag<223)Hallo[frag][2]=2*(222-frag);
}
}
setvgapalette256(&Hallo);
}
//------------------------------------------------------------------------------
void dspwrite ( unsigned char c )
{
while(inportb(0x022C)&0x80);
outportb(0x022C,c);
}
//------------------------------------------------------------------------------
void sbinit ( void )
{
unsigned short x;
inportb(0x022E);
outportb(0x0226,0x01);
inportb(0x0226);
inportb(0x0226);
inportb(0x0226);
inportb(0x0226);
outportb(0x0226,0x00);
for(x=0;x<100;x++)
{
if(inportb(0x022E)&0x80)
{
if(inportb(0x022A)==0xAA) break;
}
}
//if(x==100)
//{
// printf("Sound Blaster not found at 0220h\n");
// exit(1);
//}
}
//------------------------------------------------------------------------------
void sbmalloc ( void )
{
unsigned long physical;
data=farmalloc(80000L);
if(data==NULL)
{
printf("Memory Allocation Error\n");
exit(1);
}
physical=((unsigned long)FP_OFF(data))+(((unsigned long)FP_SEG(data))<<4);
physical+=0x0FFFFL;
physical&=0xF0000L;
aligned_physical=(physical>>16)&15;
aligned=MK_FP(((unsigned short)aligned_physical<<12)&0xF000,0);
}
//------------------------------------------------------------------------------
void sbsettc ( unsigned char tc )
// tc = time constant = 256L - (1000000UL/samples per second)
{
inportb(0x022E);
dspwrite(0x40);
dspwrite(tc);
}
//------------------------------------------------------------------------------
void sbrec ( unsigned short len )
// len = number of bytes to record to unsigned char *aligned (<=65000)
{
len--;
outportb(0x0A,0x05);
outportb(0x0C,0x00);
outportb(0x0B,0x45);
outportb(0x02,0);
outportb(0x02,0);
outportb(0x83,aligned_physical);
outportb(0x03,(unsigned char)(len&0xFF));
outportb(0x03,(unsigned char)((len>>8)&0xFF));
outportb(0x0A,0x01);
dspwrite(0x24);
dspwrite((unsigned char)(len&0xFF));
dspwrite((unsigned char)((len>>8)&0xFF));
}
//------------------------------------------------------------------------------
void sbrec2 ( unsigned short len )
// len = number of bytes to record to unsigned char *aligned (<=65000)
{
len--;
outportb(0x0A,0x05);
outportb(0x0C,0x00);
outportb(0x0B,0x45);
outportb(0x02,0);
outportb(0x02,0);
outportb(0x83,aligned_physical);
outportb(0x03,(unsigned char)(len&0xFF));
outportb(0x03,(unsigned char)((len>>8)&0xFF));
outportb(0x0A,0x01);
dspwrite(0x48);
dspwrite((unsigned char)(len&0xFF));
dspwrite((unsigned char)((len>>8)&0xFF));
dspwrite(0x99);
}
//------------------------------------------------------------------------------
unsigned short dmacount ( void )
{
unsigned short x;
x=inportb(0x03);
x|=inportb(0x03)<<8;
if(x==0xFFFF) inportb(0x022E);
return(x);
}
//------------------------------------------------------------------------------
void recording(int e,int f)
{
int m,n=Triggerbuffer -e,o;
int Smax=0,Spos=0;
if(HighSpeed)sbrec2(Triggerbuffer); else sbrec(Triggerbuffer);
while(dmacount()!=0xFFFF);
for(m=0;m<n;m++)
{
o= *(aligned+m);
if(o>Smax)Smax=o,Spos=m;
}
if(f>0)for(m=0;m<e;m++)
{
o = *(aligned+Spos+m) - f;
if(o<0)o=0;
if(o>199)o=199;
SBuffer[m]=o;
}
else for(m=0;m<e;m++)SBuffer[m] = *(aligned+Spos+m) - f;
}
void lineX00(int x,int y1,int y2)
{
int dy=y1-y2;
int m=x-1,v,w=abs(dy);
if(w<2)
{
*(VGAmem+((x-1)>>3)+80*y1)&=255-(1<<(7-((x-1)&7)));
*(VGAmem+(x>>3)+80*y2)&=255-(1<<(7-(x&7)));
return;
}
if(dy<0)
{
dy=w;
for(v=y1;v<=y2;v++)
{
w=v-y1;
w /=dy;
*(VGAmem+((m+w)>>3)+80*v)&=255-(1<<(7-((m+w)&7)));
}
}
else
{
for(v=y2;v<=y1;v++)
{
w=v-y2;
w /=dy;
*(VGAmem+((x-w)>>3)+80*v)&=255-(1<<(7-((x-w)&7)));
}
}
}
void lineX01(int x,int y1,int y2)
{
int dy=y1-y2;
int m=x-1,v,w=abs(dy);
if(w<2)
{
*(VGAmem+((x-1)>>3)+80*y1)|=1<<(7-((x-1)&7));
*(VGAmem+(x>>3)+80*y2)|=1<<(7-(x&7));
return;
}
if(dy<0)
{
dy=w;
for(v=y1;v<=y2;v++)
{
w=v-y1;
w /=dy;
*(VGAmem+((m+w)>>3)+80*v)|=1<<(7-((m+w)&7));
}
}
else
{
for(v=y2;v<=y1;v++)
{
w=v-y2;
w /=dy;
*(VGAmem+((x-w)>>3)+80*v)|=1<<(7-((x-w)&7));
}
}
}
int cool0()
{
unsigned t;
int i,m=Triggerbuffer;
Triggerbuffer=1500;
Grafik(18);
for